<template>
  <!--  <h2>目录检索</h2>-->
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="24" :xs="24">
        <el-card class="box-card">
          <div style=" display: flex;flex-direction: row;justify-content: end;    float: right;">
            <el-button v-if="showCategory" type="primary" plain icon="el-icon-arrow-up" size="mini" @click="fold">折叠
            </el-button>
            <el-button v-else type="primary" plain icon="el-icon-arrow-down" size="mini" @click="expand">展开
            </el-button>
          </div>
          <el-row :gutter="10" class="mb8" ref="queryForm" v-show="showCategory" style="width:95%; position: relative;">
            <div class="searchCheck">
              <div style="width: 8%">
                <label style="width: 80%; display: inline-block; text-align-last: justify;">分 类</label>
                <font style="width: 10%;vertical-align: top; display: inline-block;">：</font>
              </div>
              <div style="display: flex; flex-wrap: wrap; width: 90%" :style="isSize">
                <div class="block" v-for="(item, index) in classification" :key="item.value"
                  @click="handleClick(index, item)" :style="{ color: item.color, backgroundColor: item.backgroundColor }">
                  {{ item.label }}
                </div>
              </div>
            </div>

            <div class="searchCheck">
              <div style="width: 8%">
                <label style="width: 80%; display: inline-block; text-align-last: justify;">全宗</label>
                <font style="width: 10%;vertical-align: top; display: inline-block;">：</font>
              </div>
              <div style=" flex-wrap: wrap; width: 90%" :style="isSize">
                <el-select v-model="qzh" placeholder="请选择" @change="onqzhChangeTap($event)">
                  <el-option v-for="i in qzhList" :key="i.FONDS_CODE" :label="i.FONDS_NAME" :value="i.FONDS_CODE">
                  </el-option>
                </el-select>
                <div v-if="this.qzh != '-1'"
                  style="margin-top:5px;margin-bottom:15px; max-height: 140px; overflow-y: auto;">
                  <div class="block" v-for="(item, index) in archivesCategory" :key="item.value"
                    @click="handleClickArchives(index, item)"
                    :style="{ color: item.color, backgroundColor: item.backgroundColor }">
                    {{ item.label }}
                  </div>
                </div>
              </div>
            </div>
            <div class="searchCheck" v-show="showSearch">
              <div style="width: 8%">
                <label style="width: 80%; display: inline-block; text-align-last: justify;"></label>
                <font style="width: 10%;vertical-align: top; display: inline-block;"></font>
              </div>
              <div style=" flex-wrap: wrap; width: 90%" :style="isSize">
                <el-form ref="queryForm" :inline="true">
                  <el-form-item label="" v-for="(item, index) in listFrom" :key="index">
                    <span slot="label">{{ item.FIELD_CAPTION }} </span>
                    <input_item :item="item" :listFrom="listFrom" @onChangeTap="onChangeTap" :inputType="1"
                      :inputParams="queryParam"></input_item>
                  </el-form-item>
                </el-form>
              </div>
            </div>
            <div @mouseleave="hideHistory"
              style="margin-top:5px;margin-bottom:5px; max-height: 140px; overflow-y: auto;display: flex;">
              <div class="searchCheck" style="width: 50%; margin-right:1%">
                <div style="width: 17%">
                  <label style="width: 80%; display: inline-block; text-align-last: justify;">综 合 检 索</label>
                  <font style="width: 10%;vertical-align: top; display: inline-block;"> ：</font>
                </div>
                <div style="display: flex; width: 90%">
                  <el-input v-model="keyword" placeholder="请输入关键字" @mouseover.native="showHistory" :maxlength="100"
                    style="width: 100%" @keyup.enter.native="handleQuery" />
                </div>
                <div class="card" style="display: none" id="card">
                  <div style="display: flex; padding: 2%">
                    <div style="display: flex; font-size: 14px">
                      <label
                        style="display: inline-block; text-align-last: justify; height: 100%; white-space: nowrap;">检索历史</label>
                      <font style="width: 10%;vertical-align: top; display: inline-block;">：</font>
                    </div>
                    <div>
                      <span class="history" :style="isSize" type="info" v-for="(item, index) in searchHistory"
                        :key="index" @click="selectHistory(item)">{{ item }}</span>
                    </div>
                  </div>
                </div>
              </div>
              <div>
                <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>

              </div>
              <div style=" width: 20%; text-align: right;" v-show="isShowTip">
                <span style="color: grey;">单击右键可以进行收藏</span>
              </div>
            </div>
          </el-row>
          <el-row :gutter="10" class="mb8" ref="refbut" style="width: 95%;">
            <el-col :span="1.5">
              <el-button type="primary" plain icon="el-icon-edit-outline" v-hasPermi="['archive:mljs:registration']"
                @click="registration">登记</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button type="primary" plain icon="el-icon-download" v-hasPermi="['archive:mljs:allDownload']"
                @click="allDownloadTap">批量下载</el-button>
            </el-col>
            <el-col :span="1.5" style="float: right">
              <el-button type="warning" icon="el-icon-setting" circle @click="headerSettings"
                v-show="isShowButtonF || isShowButtonC" v-hasPermi="['archive:mljs:tablehead']"></el-button>
            </el-col>
          </el-row>
          <div class="showtable">

            <tableList v-if="tableHeight && tableHeaderList.length > 0" :tableHeaderList="tableHeaderList" ref="tableList"
              @handleSelectionChange="handleSelectionChange" :tableData="tableData" :loading="loading" :isSelection="true"
              :tableHeight="tableHeight" @celldblclick="celldblclick" @sortChange="sortChange" :isRetrieval="isRetrieval"
              @handleBorrow="handleBorrow" @rowcontextmenu="rowcontextmenu" @handleRegister="handleRegister"></tableList>

            <!-- <pagination  :total="total" :page.sync="queryParams.pageNum"
              :limit.sync="queryParams.pageSize" @pagination="getQuery" /> -->

              <div class="pagination-container" v-if="tableData.length > 0">
              <el-pagination :current-page="queryParams.pageNum" @current-change="handleCurrentChange"
                :page-size="queryParams.pageSize" :pager-count="11" layout="total,sizes,prev, pager, next" :total="total"
                class="custom-pagination" prev-text="上一页" next-text="下一页" background @size-change="handleSizeChange" >
              </el-pagination>
            </div>

          </div>
        </el-card>
      </el-col>

    </el-row>

    <!--start  组件详情 -->
    <jianDetailsOpen v-if="jianDetailsOpen" :open="jianDetailsOpen" :celldbData="celldbData"
      @detailsHandleClose="detailsHandleClose">
    </jianDetailsOpen>
    <!--end 组件详情 -->
    <!-- start 组卷\项目详情 -->
    <juanDetailsOpen v-if="juanDetailsOpen" :open="juanDetailsOpen" :celldbData="celldbData"
      @detailsHandleClose="detailsHandleClose" :isDelete="1"></juanDetailsOpen>
    <!-- end 组卷\项目详情 -->

    <!-- start  目录打印 -->
    <vPrint v-if="printOpen" :open="printOpen" @closeDelDialog="closeDelDialog" :tableHeaderList="tableHeaderList"
      :printList="printList"></vPrint>
    <!-- end  目录打印 -->

    <!-- start 表头设置 -->
    <transFer :title="headerTitle" :dataChecked="myDataChecked" :cities="HeaderData" @determine="submitHeader"
      @closeFilter="closeHeader" :open="headerOpen" :isHeaderOrder='true'>
    </transFer>
    <!-- end 表头设置 -->

    <!-- start 登记单 -->
    <Register :open="registerOpen" @closeDelDialog="closeRegister" ref="registerRef"></Register>
    <!-- end 登记单 -->
  </div>
</template>

<script>
import {
  getArchivesCategory,
  query,
  getcateidbyid,
  getQueryList,
  getShowList,
  addWords,
  getKeyWords,
  getInfo,
  batchInsert,
  getArchivesfication,
  queryAuthority,
  addReRegister,
  getqzhList, queryCount, download_electronics
} from "@/api/archive/retrieval/catalogueSearch";
// import tableList from "@/views/archive/retrieval/catalogueSearch/tableList";
import tableList from "@/components/tableListSearch/index.vue"
import jianDetailsOpen from '@/components/componentsJianDetails/index.vue' //件详情
import juanDetailsOpen from '@/components/componentsJuanDetails/index.vue' //卷详情
import queryCriteriaList from "@/components/queryCriteriaList/index.vue"
import input_item from "@/components/input/index.vue"
import vPrint from "@/components/printComponent/index.vue" //目录打印弹窗模板
import { addMyCollection } from "@/api/archive/liyong/myCollection";
import transFer from "@/components/transFer/index.vue"
import { addhead, gethead } from "@/api/archive/digitalizeReceive/archiveRecycleBin";
import Register from "@/views/archive/retrieval/catalogueSearch/register";
import { getTypeObject } from '@/api/archive/dict/dictManageData'
export default {
  name: "index",
  components: { Register, queryCriteriaList, tableList, jianDetailsOpen, juanDetailsOpen, vPrint, input_item, transFer },
  data() {
    return {
      showSearch: false,
      showCategory: true,
      // 分类
      classification: [
        // {label: '全部', color: 'black', backgroundColor: 'white'},
        // {value: '0', label: '件层', color: 'black', backgroundColor: 'white'},
        // {value: '1', label: '卷层', color: 'black', backgroundColor: 'white'},
        // {value: '3', label: '项目', color: 'black', backgroundColor: 'white'},
      ],
      classificationIndex: -1,
      // 档案门类
      archivesCategory: [],
      archivesCategoryIndex: -1,
      queryParams: {
        pageNum: 1,
        pageSize:10
      },
      // 输入参数
      queryParam: {},
      keyword: undefined,
      label: "",
      total: 0,
      // 是否展示历史记录
      showCard: false,
      // 历史记录
      searchHistory: [],
      listFrom: [], //查询框列表
      isRetrieval: true,
      typeOption: [],

      tableHeight: "",
      tableHeaderList: [], //table表头数据
      tableData: [],//table列表数据
      // 选中数组
      ids: [],
      id: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 遮罩层
      loading: true,
      jianDetailsOpen: false,//件详情弹窗
      juanDetailsOpen: false,//卷详情弹窗

      printOpen: false, //打印弹出传
      printList: [],
      isShowTip: false, // 是否展示提示
      size: "",
      isOnClick: true,

      // 首页的门类选择
      category: '',

      headerTitle: '表头设置',
      // 展示右侧数据
      myDataChecked: [],
      headerData: [],
      HeaderData: [],
      headerOpen: false,
      isShowButtonF: true,
      isShowButtonC: true,
      registerOpen: false,
      qzh: "",//选中的全宗号
      type: "",
      cateGoryId: "",
      qzhList: [],//全宗号列表
      selectionString: []
    }
  },
  computed: {
    isSize() {
      if (this.$store.getters.size == 'small') {
        this.size = 'font-size: 12px;'
      } else {
        this.size = 'font-size: 14px;'
      }
      return this.size
    }
  },
  mounted() {
    // 在页面加载时，获取路由传递的查询参数
    this.keyword = this.$route.query.keyword || '';
    this.category = this.$route.query.category || '';
  },
  created() {

    this.queryParams.menuId = this.$route.meta.menuId
    this.queryParams.type = null

    // 元数据方案id
    this.queryParams.groupId = null
    // 门类id
    this.queryParams.categoryId = null
    // this.getCategory()
    this.getFication()
    if (this.classification.length != 0) {
      this.classification[0].color = '#5377d7';
      this.classification[0].backgroundColor = '#e1eaff';
      this.classificationIndex = 0
    }
    if (this.archivesCategory.length != 0) {
      this.archivesCategory[0].color = '#5377d7';
      this.archivesCategory[0].backgroundColor = '#e1eaff';
      this.archivesCategoryIndex = 0
    }
    this.getqzhListPost();
    this.getAuthority()
    this.getHistory()
  },
  methods: {

    handleSizeChange(val) {
      console.log(val, "===================")
      this.queryParams.pageSize = val;
      this.queryParams.pageNum = 1
      this.getQuery();
    },
    handleCurrentChange(page) {
      this.currentPage = page;

      const firstLi = document.querySelector('.custom-pagination ul.el-pager li:first-child');
      const lastLi = document.querySelector('.custom-pagination ul.el-pager li:last-child');
      var totalPage = Math.ceil(this.total / 100)
      if (page <= 6) {
        firstLi.style.display = 'inline-block';
      } else {
        firstLi.style.display = 'none';
      }
      if (totalPage - page <= 4) {

        lastLi.style.display = 'inline-block';
      } else {
        lastLi.style.display = 'none'
      }

      this.queryParams.pageNum = page;

      this.getQuery();

    },

    //批量下载
    allDownloadTap() {
      var that = this;


      if (!this.multiple) {

        var data = [];
        for (var i in this.selectionString) {
          data.push({
            "subtablename": this.selectionString[i].SUB_TABLE_NAME,
            "id": this.selectionString[i].DA_ID
          })


        }

      

          var dalist={
            dalist:data
          }
         var dalist= JSON.stringify(dalist)
              this.download('/archive/list/query/download/electronics', {dalist}
            , `wjb_${new Date().getTime()}.zip`)
         
  
      } else {
        this.$modal.msgWarning('请选择下载数据哦！')
      }


    },
    //全宗号列表
    getqzhListPost() {
      getqzhList(this.$route.meta.menuId).then(res => {
        if (res.code == 200) {
          this.qzhList = res.data;
          this.qzh = res.data[0].FONDS_CODE;
          this.queryParams.qzh = res.data[0].FONDS_CODE;
          this.getCategory();
          // this.handleQuery()
        }
      })
    },
    //全宗号列表下拉事件
    onqzhChangeTap(val) {
      this.queryParams.fileField = undefined;
      this.queryParams.groupId = undefined;

      this.keyword = undefined
      this.tags = []
      this.queryParams.queryParameters = undefined
      this.queryParams.pageNum = 1
      this.queryParams.pageSize = 10
      this.queryParam = {};
      this.queryParams.qzh = val;
      this.showSearch = false;
      this.getCategory()
    },
    // 获取检索历史
    getHistory() {
      getInfo().then(res => {
        this.form = {
          // userName: res.user.userName,
          userId: res.user.userId,
          menuId: this.$route.meta.menuId
        }
        getKeyWords(this.form).then(response => {
          this.searchHistory = response.data
        })
      })
    },
    // 获取收藏权限
    getAuthority() {
      queryAuthority().then(response => {
        if (response.data == true) {
          this.isShowTip = true
        } else {
          this.isShowTip = false
        }
      })
    },
    //动态设置table的高度
    tableHeightData() {
      this.$nextTick(
        () => {
          let h = document.documentElement.clientHeight
          h = h - 240
          if (this.$refs.queryForm) { // 页面上如果有面包屑区域徐减去它的高度
            h = h - this.$refs.queryForm.$el.offsetHeight
          }

          if (this.$refs.refbut) { // 页面上如果有分页区域徐减去它的高度
            h = h - this.$refs.refbut.$el.offsetHeight
          }
          console.log(h, this.$refs.queryForm.$el.offsetHeight, this.$refs.refbut.$el.offsetHeight)
          this.tableHeight = h > 380 ? h : 380 // 根据自己项目定高度
          console.log(this.tableHeight)
          return h
        }
      )
    },
    //折叠事件
    fold() {
      this.showCategory = false
    },
    //展开事件
    expand() {
      this.showCategory = true
    },
    showHistory() {
      var d1 = document.getElementById('card')
      d1.style.cssText = 'display: block;'
    },
    hideHistory() {
      var d1 = document.getElementById('card')
      d1.style.cssText = 'display: none;'
    },
    selectHistory(item) {
      this.keyword = item;
    },
    // 分类变换
    handleClick(index, value) {
      this.showSearch = false;
      // if (this.isOnClick) {
      if (this.$refs.tableList != undefined) {
        this.$refs.tableList.clearSort()
      }
      this.isOnClick = false
      if (value.label == '全部') {
        this.isShowButtonF = true
      } else {
        this.isShowButtonF = false
      }
      if (this.classificationIndex !== -1) {
        // 恢复上次点击的div为黑色并去掉下划线
        this.classification[this.classificationIndex].color = '#606266';
        this.classification[this.classificationIndex].backgroundColor = 'white';
      }
      // 将当前点击的div变为蓝色并添加下划线
      this.classification[index].color = '#5377d7';
      this.classification[index].backgroundColor = '#e1eaff';

      // 更新classificationIndex
      this.classificationIndex = index;
      this.queryParams.type = value.value
      this.type = value.value;
      // 切换标签页时移除门类id,元数据方案id
      this.queryParams.categoryId = undefined;
      this.queryParams.groupId = undefined;
      // 清空排序
      this.queryParams.order = undefined
      this.queryParams.files = undefined
      // this.loading = true;
      this.keyword = undefined
      this.queryParams.queryParams = undefined
      this.queryParams.pageNum = 1
      this.queryParams.pageSize = 10
      this.queryParam = {};
      this.getCategory()
      this.isShowButtonC = true
      // } else {
      //   this.$message({ message: '重复点击，请稍后再试!', type: 'warning' })
      // }
    },
    // 获取门类
    getCategory() {

      getArchivesCategory({ type: this.queryParams.type, menuId: this.queryParams.menuId, qzh: this.queryParams.qzh }).then(response => {
        var data = response.data.categoryList.map(item => {
          return {
            // 门类id
            value: item.ID,
            // 门类名称
            label: item.NAME,
            // 元数据方案id
            id: item.GROUP_ID,
            // 类型
            type: item.TYPE,
            color: '#606266',
            backgroundColor: 'white'
          }
        })
        this.archivesCategory = []
        this.archivesCategory = [{
          label: "全部",
          color: '#606266',
          backgroundColor: 'white',
          value: '-1'
        }]
        this.archivesCategory.push(...data)
        if (this.$route.query.keyword != undefined) {
          if (this.category.value != undefined) {
            for (let i = 0; i < this.archivesCategory.length; i++) {
              if (this.archivesCategory[i].value == this.category.value) {
                this.archivesCategory[i].color = '#5377d7';
                this.archivesCategory[i].backgroundColor = '#e1eaff';
                this.archivesCategoryIndex = i
                this.queryParams.groupId = this.category.id
                // 门类id
                this.queryParams.categoryId = this.category.value
                // label
                this.label = this.category.label
                this.getSearch()
                // this.handleQuery()
              }
            }
          } else {
            if (this.archivesCategory.length != 0) {
              this.archivesCategory[0].color = '#5377d7';
              this.archivesCategory[0].backgroundColor = '#e1eaff';
              this.archivesCategoryIndex = 0
            }
            this.getSearch()
            // this.handleQuery()
          }
        } else {
          if (this.archivesCategory.length != 0) {
            this.archivesCategory[0].color = '#5377d7';
            this.archivesCategory[0].backgroundColor = '#e1eaff';
            this.archivesCategoryIndex = 0
            this.queryParams.categoryId = '-1'
          }
          this.getSearch()
          // this.handleQuery()
        }
      })
    },
    // 获取分类
    getFication() {
      getArchivesfication(this.queryParams.menuId).then(response => {
        var data = response.data.map(item => {
          return {
            value: item.value,
            label: item.label,
            color: '#606266',
            backgroundColor: 'white'
          }
        })
        this.classification = []
        this.classification = [{
          label: "全部",
          color: '#606266',
          backgroundColor: 'white',
          value: '-1',
        }]
        this.classification.push(...data)
        if (this.classification.length != 0) {
          this.classification[0].color = '#5377d7';
          this.classification[0].backgroundColor = '#e1eaff';
          this.classificationIndex = 0
          this.queryParams.type = '-1'
          this.type = "-1"
        }

      })
    },
    // 档案门类变换
    handleClickArchives(index, value) {
      // if (this.isOnClick) {
      if (this.$refs.tableList != undefined) {
        this.$refs.tableList.clearSort()
      }
      this.isOnClick = false
      if (this.archivesCategoryIndex !== -1) {
        // 恢复上次点击的div为黑色并去掉下划线
        this.archivesCategory[this.archivesCategoryIndex].color = '#606266';
        this.archivesCategory[this.archivesCategoryIndex].backgroundColor = 'white';
      }
      // 将当前点击的div变为蓝色并添加下划线
      this.archivesCategory[index].color = '#5377d7';
      this.archivesCategory[index].backgroundColor = '#e1eaff';

      // 更新archivesCategoryIndex
      this.archivesCategoryIndex = index;
      // 元数据方案id
      this.queryParams.groupId = value.id
      // 门类id
      this.queryParams.categoryId = value.value
      this.cateGoryId = value.value;
      // label
      this.label = value.label
      if (value.label == '全部') {
        this.isShowButtonC = true
      } else {
        this.isShowButtonC = false
      }
      // 清空排序
      this.queryParams.order = undefined
      this.queryParams.files = undefined
      // this.loading = true;
      this.keyword = undefined
      this.queryParams.queryParams = undefined
      this.queryParams.pageNum = 1
      this.queryParams.pageSize = 10
      this.queryParam = {};
      this.getSearch()
      // this.handleQuery()
      // } else {
      //   this.$message({ message: '重复点击，请稍后再试!', type: 'warning' })
      // }
    },
    // 搜索条件
    getSearch() {
      this.listFrom = []
      if (this.queryParams.categoryId != undefined && this.queryParams.menuId != undefined && this.queryParams.type != undefined) {
        getQueryList(this.queryParams).then(response => {
          console.log(response, response.data, "liuhairont")
          if (response.data) {
            this.showSearch = true
            this.listFrom = response.data;
          } else {
            this.showSearch = false
          }

        })
      }
    },
    // 表头
    getTableList() {
      getShowList(this.queryParams).then(response => {
        if (response.data != undefined) {
          this.tableHeaderList = response.data;
          var files = []
          for (var i in response.data) {
            files.push(response.data[i].FIELD_NAME)
          }
          this.queryParams.files = files.toString()
        }

        this.getQuery();

      })
    },
    // 表格
    getQuery() {
      query(this.queryParams).then(response => {
        if (response.rows == null) {
          response.rows = []
        }
        for (let i = 0; i < response.rows.length; i++) {
          var data = []
          this.typeOption = []
          if (response.rows[i].EFILE_COUNT > 0) {
            // console.log(response.rows[i].EFILE_COUNT)
            data.push(...[
              { value: '1', label: '电子件' }
            ])
          }
          if (response.rows[i].IS_ENTITY == '1') {
            data.push(...[
              { value: '0', label: '实体件' }
            ])
          }
          if (response.rows[i].EFILE_COUNT < 0 && response.rows[i].IS_ENTITY != '1') {
            data = []
          }
          this.typeOption.push(...data)
          response.rows[i].typeOption = this.typeOption
          if (response.rows[i].typeOption.length > 0) {
            response.rows[i].borrowType = response.rows[i].typeOption[0].value
          }
        }
        this.tableData = response.rows


        //数据列表shoWType==5匹配字典
        var headerlist = [];
        for (var i = 0; i < this.tableHeaderList.length; i++) {
          if (this.tableHeaderList[i].SHOWTYPE.toString().indexOf('5') != -1) {
            this.tableHeaderList[i].SHOWTYPE = 5
          }
          if (this.tableHeaderList[i].SHOWTYPE == 5) {
            headerlist.push(this.tableHeaderList[i].FIELD_NAME)
          }
        }
        // console.log(headerlist,"klsdjfklsdjfklsdjfklsdjfklsd")
        getTypeObject(headerlist).then((res) => {
          this.dictList = res.data;
          for (var j in this.tableHeaderList) { //获取表头字段
            if (this.tableHeaderList[j].SHOWTYPE == 5) { //判断字段类型是5==下拉 的情况下，获取字典渲染
              for (var i in this.tableData) {
                for (var n in this.tableData[i]) {
                  if (n == this.tableHeaderList[j].FIELD_NAME) {
                    console.log(this.tableData[i][n], n)
                    for (var l in this.dictList[n]) {
                      if (this.dictList[n][l].dictValue == this.tableData[i][n]) {
                        this.tableData[i][n] = this.dictList[n][l].dictLabel
                      }
                    }
                  }

                }

              }
            }

          }
          // console.log(this.tableData, "liuhiaorng")
          if (this.keyword != "" && this.keyword != undefined) {
            const words = this.keyword.match(/\S+/g);
            if (words != null) {
              this.tableData.forEach(row => {
                // 遍历每一列数据
                Object.keys(row).forEach(column => {
                  if (column != 'is_borrowing_car' && column != 'SUB_TABLE_NAME' && column != 'DA_ID' && column != 'borrowType' && column != 'CREATE_ID') {
                    var value = ''
                    if (row[column] != null) {
                      if (typeof (row[column]) == 'string') {
                        value = row[column];
                      } else {
                        value = row[column].toString();
                      }
                    }
                    // 判断当前列数据是否包含查询条件中的任意一个元素
                    let matchFound = words.some(item => value.includes(item));

                    if (matchFound) {
                      // 使用<span>标签将匹配到的字段改为红色
                      words.forEach(item => {
                        // let highlightedValue = value.replace(new RegExp(item, "gi"), "<span style='color: red;'>$&</span>");
                        let escapedItem = item.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&')
                        let highlightedValue = value.replace(new RegExp(escapedItem, "gi"), "<span style='color: red;'>$&</span>");
                        value = highlightedValue;
                      });
                      row[column] = value;
                    }
                  }
                });
              });
            }
          }
                 this.getTotal();
          // console.log(this.tableData)
          // this.total = response.total;
          this.loading = false;
          setTimeout(() => {
            this.isOnClick = true
          }, 300)
          this.tableHeightData();
        }).catch(() => {

          this.loading = false;
          setTimeout(() => {
            this.isOnClick = true
          }, 300)
        })
      })

    },
    //获取总条数
    getTotal() {
      queryCount(this.queryParams).then(res => {

        this.total = parseInt(res.data)
      })
    },
    //是否选择数据
    handleSelectionChange(ids, single, multiple, selection) {
      this.ids = ids.toString();
      this.single = single;
      this.multiple = multiple;
      this.id = selection.map(item => item.DA_ID).toString()
      this.selectionString = selection
    },
    //onChangeTap时间
    onChangeTap(data) {
      var dataArr = ""
      if (data.val != undefined) {
        dataArr = data.queryParams;
      } else {
        dataArr = data;
      }
      // if (this.queryParams.length > 0) {
      //   for (var i in this.queryParams) {
      //     if (Object.keys(this.queryParams[i]).toString() == Object.keys(data).toString()) {
      //       this.queryParams.splice(i, 1)
      //     }
      //   }
      //   this.queryParams = dataArr;
      // } else {
      //   this.queryParams = dataArr;
      // }
      // console.log(this.queryParams)
    },
    handleQuery() {
      this.loading = true;
      // this.queryParams.pageNum = 1
      // this.queryParams.pageSize = 10;
      // this.queryParams.qzh=this.qzh;
      // this.queryParams.type=this.type;
      // this.queryParams.cateGoryId=this.cateGoryId;
      // this.queryParams.categoryId=this.cateGoryId;
      // this.queryParams.menuId=this.$route.meta.menuId
      this.queryParams.order = undefined;
      if (this.$refs.tableList != undefined) {
        this.$refs.tableList.clearSort()
      }
      this.hideHistory()
      var searchcolumn = []
      for (var k in this.listFrom) {
        for (var i in this.queryParam) {
          if (this.queryParam[i] != null) {
            if (this.listFrom[k].FIELD_NAME == i) {
              if (this.listFrom[k].SHOWTYPE == 3 && this.listFrom[k].IS_QUERY == 4) {
                searchcolumn.push({
                  "queryType": this.listFrom[k].IS_QUERY,
                  "showType": this.listFrom[k].SHOWTYPE,
                  "column": this.listFrom[k].FIELD_NAME,
                  "value": this.queryParam[i][0],
                  "valueTwo": this.queryParam[i][1],
                })
              } else if (this.listFrom[k].SHOWTYPE == 7 || this.listFrom[k].SHOWTYPE == 8 || this.listFrom[k].SHOWTYPE == 10) {
                searchcolumn.push({
                  "queryType": this.listFrom[k].IS_QUERY,
                  "showType": this.listFrom[k].SHOWTYPE,
                  "column": this.listFrom[k].FIELD_NAME + "_ID",
                  "value": this.queryParam[i + "_ID"],

                })
              } else {
                searchcolumn.push({
                  "queryType": this.listFrom[k].IS_QUERY,
                  "showType": this.listFrom[k].SHOWTYPE,
                  "column": this.listFrom[k].FIELD_NAME,
                  "value": this.queryParam[i],
                })
              }
            }
          }
        }
      }



      if (searchcolumn != undefined && searchcolumn.length != 0) {
        var column = searchcolumn.filter(item => {
          return item.value !== ''
        })
        this.queryParams.queryParams = column
      } else {
        this.queryParams.queryParams = []
      }




      if (this.keyword != "" && this.keyword != undefined) {
        const words = this.keyword.split(/\s+/);
        var arr = []
        for (let i = 0; i < words.length; i++) {
          arr.push({
            queryType: 8,
            value: words[i]
          })
        }
        this.saveKeyword(this.keyword)
        this.queryParams.queryParams.push(...arr)
      }
      console.log(this.queryParams.queryParams, this.queryParams, "00")

      this.getTableList();
      this.getHistory();
    },
    resetQuery() {
      this.keyword = undefined
      this.queryParams.queryParams = undefined
      this.queryParam = {};
      this.queryParams.order = undefined;
      if (this.$refs.tableList != undefined) {
        this.$refs.tableList.clearSort()
      }
      this.handleQuery();
    },
    // 保存综合检索关键字
    saveKeyword(keyword) {
      this.form = {
        keyWords: keyword,
        menuId: this.$route.meta.menuId
      }
      addWords(this.form).then(response => {
      })
    },
    //双击列表进入详情页面
    celldblclick(row) {
      this.subStr = this.getLastIndexOf(row.SUB_TABLE_NAME);
      var level = "";
      var type = "";
      var label = "";
      var regex = /<span style='color: red;'>|<\/span>/g;
      if (this.getLastIndexOf(row.SUB_TABLE_NAME) == "F") {  //F 件
        level = 0
        type = "f"
        // label = row.TITLE.replace(regex, '');
        if (row.TITLE != undefined && row.TITLE != null && row.TITLE != '') {
          label = row.TITLE.replace(regex, '');
        }
      } else if (this.getLastIndexOf(row.SUB_TABLE_NAME) == "V") { //卷
        level = 1
        type = "v"
        // label = row.TITLE.replace(regex, '');
        if (row.TITLE != undefined && row.TITLE != null && row.TITLE != '') {
          label = row.TITLE.replace(regex, '');
        }
      } else { //项目
        level = 3
        type = "x"
        // label = row.XMMC.replace(regex, '');
        if (row.XMMC != undefined && row.XMMC != null && row.XMMC != '') {
          label = row.XMMC.replace(regex, '');
        }
      }
      this.form = {
        id: row.DA_ID,
        type: type
      }

      getcateidbyid(this.form).then(response => {
        this.celldbData = {
          id: row.DA_ID,
          categoryId: response.data,
          menuId: this.$route.meta.menuId,
          sub_table_name: row.SUB_TABLE_NAME,
          label: label,
          level: level,
          ifSub_table_name: row.SUB_TABLE_NAME,
          isDel: "0",  //判断是回收站数据还是接收收据 isDel:1  回收站    isDel:0 //离线接收、档案接收、在线接收
          tableHeaderList: this.tableHeaderList,
          isBorrowingCar: row.is_borrowing_car, //是否显示购物车
          isShowjieyue: true,
        }
        this.$nextTick(() => {
          if (this.subStr == "F") {  //F 进入件详情
            this.jianDetailsOpen = true;
          } else { //进入卷详情 和项目详情
            this.juanDetailsOpen = true
          }
        })
      })
    },
    // 获取字符串中最后一个_前面的内容和获取最后一个"_"之后的内容
    getLastIndexOf(sub_table_name) {
      // 获取字符串中最后一个_前面的内容:
      var str = sub_table_name;
      var index = str.lastIndexOf("_");
      var strData = str.substring(0, index);
      //获取最后一个"_"之后的内容
      var index1 = strData.lastIndexOf("_");
      strData = strData.substring(index1 + 1, strData.length);
      return strData;
    },
    //关闭详情页面
    detailsHandleClose() {
      this.jianDetailsOpen = false;
      this.juanDetailsOpen = false;
    },
    //排序
    sortChange(val) {
      // console.log(val, "ksdfjkl")
      this.queryParams.order = val;
      // console.log(this.queryParams, "+++")
      this.getQuery();
    },
    // 加入借阅车
    handleBorrow(row) {
      var isdaBox = ""
      var type = "";
      var regex = /<span style='color: red;'>|<\/span>/g;
      if (this.getLastIndexOf(row.SUB_TABLE_NAME) == "F") {  //F 件
        isdaBox = "0"
        type = "f"
      } else if (this.getLastIndexOf(row.SUB_TABLE_NAME) == "V") { //卷
        isdaBox = "1"
        type = "v"
      } else { //项目
        isdaBox = "1"
        type = "x"
      }
      this.form = {
        id: row.DA_ID,
        type: type
      }
      getcateidbyid(this.form).then(response => {
        const data = [{
          daType: row.borrowType,
          categoryId: response.data,
          daId: row.DA_ID,
          isdaBox: isdaBox,
          archiveType: type,
          subTableName: row.SUB_TABLE_NAME
        }]
        batchInsert(data).then(response => {
          this.$modal.msgSuccess("加入借阅车成功")
        })
      })
    },
    // 目录
    printTap() {
      this.printList = [];
      if (this.id != undefined && this.id != null && this.id != "") {
        this.printOpen = true
        var idsData = this.id.split(",")
        for (var i in this.tableData) {
          for (var j in idsData) {
            if (this.tableData[i].DA_ID == idsData[j]) {
              this.printList.push(this.tableData[i])
            }
          }
        }
      } else {
        this.$message({ message: '请选择要打印的数据哦', type: 'warning' })
      }
    },
    //关闭
    closeDelDialog() {
      this.printOpen = false;//打印
    },
    rowcontextmenu(row) {
      var label = ''
      var IS_EFILE = ''
      var IS_ENTITY = ''
      var regex = /<span style='color: red;'>|<\/span>/g;
      if (this.getLastIndexOf(row.SUB_TABLE_NAME) == "F") {  //F 件
        if (row.TITLE != undefined && row.TITLE != null && row.TITLE != '') {
          label = row.TITLE.replace(regex, '');
        }
      } else if (this.getLastIndexOf(row.SUB_TABLE_NAME) == "V") { //卷
        if (row.TITLE != undefined && row.TITLE != null && row.TITLE != '') {
          label = row.TITLE.replace(regex, '');
        }
      } else { //项目
        if (row.XMMC != undefined && row.XMMC != null && row.XMMC != '') {
          label = row.XMMC.replace(regex, '');
        }
      }
      var dh = row.DH
      if (row.DH != undefined && row.DH != '' && row.DH != null) {
        dh = dh.replace(regex, '')
      }
      if (row.EFILE_COUNT > 0) {
        IS_EFILE = '是'
      } else {
        IS_EFILE = '否'
      }
      if (row.IS_ENTITY == '1' || row.IS_ENTITY == '是') {
        IS_ENTITY = '是'
      } else {
        IS_ENTITY = '否'
      }
      this.form = {
        subTableName: row.SUB_TABLE_NAME,
        daNum: dh,
        daContent: label,
        daId: row.DA_ID,
        isEfile: IS_EFILE,
        isEntity: IS_ENTITY
      }
      console.log(this.form)
      if (this.isShowTip) {
        this.$modal.confirm('是否确认收藏所选档案？').then(function () {
        }).then(() => {
          addMyCollection(this.form).then(res => {
            if (res.code == "200") {
              this.$modal.msgSuccess("收藏成功");
            }
          })
        }).catch(() => {
        });
      }
    },

    // 表头设置
    headerSettings() {
      this.headerOpen = true
      this.myDataChecked = []
      var form = JSON.parse(JSON.stringify(this.queryParams))
      // 1: 门类全部   分类全部              左: null  null    右: -1 -1
      // 2: 门类全部  分类选层次(件卷项目)     左: null   0/1/3    右: -1   0/1/3
      // 3: 门类选择   分类全部              左: id  null        右: id   -1
      if (this.queryParams.categoryId == '-1') {
        form.categoryId = null
      } else {
        form.categoryId = this.queryParams.categoryId
      }
      if (this.queryParams.type == '-1') {
        form.type = null
      } else {
        form.type = this.queryParams.type
      }
      getShowList(form).then(response => {
        if (response.data != undefined) {
          this.headerData = response.data.map((item, index) => {
            return {
              fieldCaption: item.FIELD_CAPTION,
              fieldName: item.FIELD_NAME,
              key: index,
              isOrder: 'none'
            }
          })
          gethead({ tablemenuId: this.$route.meta.menuId, zltype: this.queryParams.type, cateGoryId: this.queryParams.categoryId, qzh: this.queryParams.qzh }).then(res => {
            if (res.msg != null) {
              var arr = res.msg.split(',')
              const result = arr.reduce((acc, item) => {
                const [key, value] = item.split(" ");
                acc[key] = value;
                return acc;
              }, {});
              for (let i = 0; i < arr.length; i++) {
                if (this.headerData.filter((item) => item.fieldName == Object.keys(result)[i]).length != 0) {
                  const data = this.headerData.filter((item) => item.fieldName == Object.keys(result)[i])
                  data[0].isOrder = Object.values(result)[i]
                  this.myDataChecked = this.myDataChecked.concat(data)
                }
              }
            }
            this.HeaderData = this.headerData
          })
        }
      })
    },
    // 保存
    submitHeader(value, isOrder) {
      this.form = {
        tablemenuId: this.$route.meta.menuId,
      }
      if (this.queryParams.categoryId != undefined) {
        this.form.cateGoryId = this.queryParams.categoryId
      } else {
        this.form.cateGoryId = '-1'
        this.queryParams.categoryId = '-1'
      }
      if (this.queryParams.type != undefined) {
        this.form.zltype = this.queryParams.type
      } else {
        this.form.zltype = '-1'
        this.queryParams.type = '-1'
      }
      var arr = []
      for (var j = 0; j < value.length; j++) {
        for (var i = 0; i < isOrder.length; i++) {
          if (isOrder[i].key == value[j]) {
            const str = isOrder[i].code + "$" + isOrder[i].isOrder
            arr.push(str)
          }
        }
      }
      this.form.content = arr.toString()
      this.form.qzh = this.qzh;
      addhead(this.form).then(res => {
        this.headerOpen = false
        this.myDataChecked = []
        this.headerData = []
        this.getTableList()
      })
    },
    closeHeader() {
      this.headerOpen = false
      this.myDataChecked = []
      this.headerData = []
    },

    // 借阅登记单
    handleRegister(row) {
      var that = this;
      var label = ''
      var type = "";
      var regex = /<span style='color: red;'>|<\/span>/g;
      if (that.getLastIndexOf(row.SUB_TABLE_NAME) == "F") {  //F 件
        if (row.TITLE != undefined && row.TITLE != null && row.TITLE != '') {
          label = row.TITLE.replace(regex, '');
        }
        type = "f"
      } else if (that.getLastIndexOf(row.SUB_TABLE_NAME) == "V") { //卷
        if (row.TITLE != undefined && row.TITLE != null && row.TITLE != '') {
          label = row.TITLE.replace(regex, '');
        }
        type = "v"
      } else { //项目
        if (row.XMMC != undefined && row.XMMC != null && row.XMMC != '') {
          label = row.XMMC.replace(regex, '');
        }
        type = "x"
      }
      var dh = row.DH
      if (row.DH != undefined && row.DH != '' && row.DH != null) {
        dh = dh.replace(regex, '')
      }

      var rq = row.RQ
      if (row.RQ != undefined && row.RQ != '' && row.RQ != null) {
        rq = rq.replace(regex, '')
      }

      var bgqc = row.BGQX
      if (row.BGQX != undefined && row.BGQX != '' && row.BGQX != null) {
        bgqc = bgqc.replace(regex, '')
      }



      var dataArr = {
        BGQX: bgqc,
        BMQX: row.BMQX,
        CREATE_ID: row.CREATE_ID,
        DA_ID: row.DA_ID,
        DH: dh,
        EFILE_COUNT: row.EFILE_COUNT,
        GDCS: row.GDCS,
        GDCS_ID: row.GDCS_ID,
        IS_ENTITY: row.IS_ENTITY,
        IS_OPENS: row.IS_OPENS,
        MJ: row.MJ,
        ND: row.ND,
        RQ: rq,
        SUB_TABLE_NAME: row.SUB_TABLE_NAME,
        TITLE: label,
        ZRZ: row.ZRZ,
        borrowType: row.borrowType,
        categoryId: row.categoryId,
        is_borrowing_car: row.is_borrowing_car,
        typeOption: row.typeOption
      }
      var data = {
        id: row.DA_ID,
        type: type
      }
      getcateidbyid(data).then(response => {
        row.categoryId = response.data
        dataArr.categoryId = row.categoryId
        this.form = {
          daId: row.DA_ID,
          title: label,
          dh: dh,
          daMsg: JSON.stringify(dataArr),
          subTableName: row.SUB_TABLE_NAME,
        }
        addReRegister(this.form).then(res => {
          this.$modal.msgSuccess('添加登记单档案成功')
        })
      })
    },
    // 登记
    registration() {
      this.registerOpen = true
      this.$nextTick(() => {   //此函数执行时所有的DOM挂载和渲染都已完成
        this.$refs.registerRef.init();     //获取子组件中init方法并将父组件数据传递给子组件
      });
    },
    closeRegister() {
      this.registerOpen = false
    }
  }
}
</script>

<style lang="scss" scoped>
.box-card {
  height: calc(100vh - 120px) !important;
  overflow-y: scroll;
}

.searchCheck {
  //margin: 15px auto 0px;
  margin-bottom: 2px;
  max-height: 200px;
  // overflow-y: auto;
  display: flex;
  line-height: 36px;
  font-size: 14px;
  color: #606266;
}

.block {
  padding: 3px 8px 3px 8px;
  white-space: nowrap;
  border-radius: 2px;
  border: solid 1px #e3e3e3;
  // font-size: 14px;
  color: #606266;
  text-align: center;
  margin: 0 8px 4px 0;
  display: inline-table;
  line-height: 25px;
}

.searchCheck .el-input {
  margin-bottom: 2px;
  width: 90%
}

.card {
  overflow: hidden;
  outline: none;
  width: 42%;
  display: flex;
  margin-left: 7.5%;
  border: 1px solid #ddd;
  box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.1);
  border-radius: 2px;
  height: 100px;
  overflow-y: scroll;
  z-index: 9999;
  transform: translate(0%, 40%);
  background-color: white;
  position: absolute;
}

.card .el-card__body {
  display: flex;
}

.history {
  padding: 3px 8px 3px 8px;
  border-radius: 2px;
  font-size: 10px;
  margin: 0 8px 4px 0;
  display: inline-table;
  height: 10px;
  line-height: 12px;
  color: #999;
  border: 1px solid #ccc;
  background-color: #f4f4f5;
}

.history:hover {
  background-color: white;
}


::v-deep .custom-pagination .btn-quickprev {
  display: none !important;

}

::v-deep .custom-pagination .btn-quicknext {
  display: none !important;
}

::v-deep .custom-pagination ul.el-pager li:last-child {
  display: none;
}
</style>
